'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 9_study_extra_with_Qa.py
* @Time: 2025/11/3
* @All Rights Reserve By Brtc
'''
import dotenv
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
from langchain_openai import ChatOpenAI
from pydantic import BaseModel, Field

dotenv.load_dotenv()

class QAExtra(BaseModel):
    """一个问答对工具， 传递对应的假设性问题 生成 问题 + 答案"""
    question:str = Field(description="假设性问题")
    answer:str = Field(description="假设性对应的答案")

llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
structured_llm = llm.with_structured_output(QAExtra)
prompt = ChatPromptTemplate.from_messages([
    ("system", "请从用户传递的query中提取假设性问题+答案"),
    ("human", "{query}")
])
chain = {"query":RunnablePassthrough()} | prompt | structured_llm
obj = chain.invoke("我叫博小睿, 喜欢写代码")


print(type(obj))
print(obj)